//
//  SYInfinityAPI.swift
//  Entrance
//
//  Created by chunhuiLai on 2018/1/11.
//  Copyright © 2018年 chunhuiLai. All rights reserved.
//

import Foundation
import Moya

public enum SYInfinityAPI {
    case zen
    case userProfile(String)
}

extension SYInfinityAPI: TargetType {
    public var baseURL: URL {
        return URL(string: SYNetworkConfigs.baseUrl)!
    }
    
    public var path: String {
        switch self {
        case .zen:
            return "/zen"
        case .userProfile:
            return "/userProfile"
        }
    }
    
    public var method: Moya.Method {
        return .post
    }
    
    public var sampleData: Data {
        return "sample".data(using: String.Encoding.utf8)!
    }
    
    public var task: Task {
        switch self {
        case .zen:
            return .requestPlain
        case .userProfile(let name):
            let params: JSONDictionary = ["name" : name]
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        }
    }
    
    public var headers: [String : String]? {
        return nil
    }

}

extension TargetType {
    var urlString: String {
        return baseURL.appendingPathComponent(path).absoluteString
    }
}
